Refactor: Leverage Native Gem Types Across All Providers#271
Merged
TonsOfFun merged 9 commits intoactiveagents:mainfrom Nov 16, 2025
Merged
Refactor: Leverage Native Gem Types Across All Providers#271TonsOfFun merged 9 commits intoactiveagents:mainfrom
TonsOfFun merged 9 commits intoactiveagents:mainfrom
Conversation
…er normalization and cleanup processes
12b4f1a to
02404dc
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR executes a major architectural refactoring of ActiveAgent's provider integration layer, replacing ~6,660 lines of custom type definitions with ~3,150 lines of transformation utilities that leverage native types from official provider gems (anthropic, openai, and ollama via OpenAI compatibility). The refactoring maintains backward compatibility while significantly reducing maintenance burden.
Key Changes:
- Introduced
Transformsmodules for each provider to handle bidirectional parameter transformation - Refactored Request classes to use
SimpleDelegatorpattern wrapping native gem types - Updated provider implementations to work with native gem objects instead of custom classes
- Removed custom message, content, tool, and input type hierarchies across all providers
Reviewed Changes
Copilot reviewed 173 out of 175 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lib/active_agent/providers/open_router/transforms.rb |
New transform module handling OpenRouter-specific extensions (plugins, provider preferences) with OpenAI base compatibility |
lib/active_agent/providers/open_router/request.rb |
Refactored to SimpleDelegator wrapping OpenAI gem with OpenRouter parameter extensions |
lib/active_agent/providers/open_router/requests/*.rb |
Enhanced documentation for response_format, provider_preferences, prediction, plugins with detailed examples |
lib/active_agent/providers/open_router/options.rb |
Enhanced documentation for Options class with Rails auto-configuration details |
lib/active_agent/providers/open_ai/responses/transforms.rb |
New transform module for Responses API with input normalization and response_format mapping |
lib/active_agent/providers/open_ai/responses/request.rb |
Refactored to SimpleDelegator with field mapping (messages→input, response_format→text) |
lib/active_agent/providers/open_ai/responses_provider.rb |
Updated to use native gem types and Transforms for hash conversion |
lib/active_agent/providers/open_ai/embedding/transforms.rb |
New transform module for embedding parameter normalization |
lib/active_agent/providers/open_ai/embedding/request.rb |
Refactored to SimpleDelegator wrapping EmbeddingCreateParams |
lib/active_agent/providers/open_ai/chat/transforms.rb |
Comprehensive transform module handling message normalization, shorthand formats, and content merging |
lib/active_agent/providers/open_ai/chat/request.rb |
Refactored to SimpleDelegator wrapping CompletionCreateParams |
lib/active_agent/providers/open_ai/chat_provider.rb |
Updated to use native gem message types and Transforms for tool message creation |
lib/active_agent/providers/ollama/embedding/transforms.rb |
New transform module for Ollama embeddings with OpenAI compatibility |
test/docs/providers/anthropic_examples_test.rb |
Fixed assertion argument order (actual vs expected) |
| VCR cassettes | Updated with new request/response formats reflecting native gem usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR represents a major refactoring of ActiveAgent's provider integration layer, replacing our custom type definitions with native types from the official provider gems (
anthropic,openai, andollamavia OpenAI compatibility). This change significantly reduces our maintenance burden while improving reliability and future compatibility.Key Changes
Architecture Shift
Significant Code Reduction
Provider-by-Provider Refactoring
1. Anthropic Provider (a9ef325)
Anthropic::Transformsmodule (+353 lines) for bidirectional parameter transformationAnthropicgem's nativeAnthropic::Messages::MessageCreateParams2. OpenAI Responses Provider (0b1798d)
OpenAI::Responses::Transforms(+228 lines) for response format normalizationOpenAI::ResponseCreateParametersdirectly3. OpenAI Chat Provider (4671886)
OpenAI::Chat::Transforms(+364 lines) for message and response_format handlingOpenAI::ChatCompletionParametersfrom the gem4. OpenAI Embeddings (94dbd07)
OpenAI::Embedding::Transforms(+88 lines) for parameter normalizationOpenAI::EmbeddingParametersnatively5. OpenRouter Provider (ef7d870)
OpenRouter::Transforms(+134 lines) for provider-specific extensions6. Ollama Provider (7088a6f)
Ollama::Chat::Transforms(+135 lines) andOllama::Embedding::Transforms(+160 lines)7. Request Normalization (02404dc)
Benefits
1. Reduced Maintenance Burden
2. Improved Reliability
3. Better Performance
4. Enhanced Developer Experience
Transform Modules
Each provider now has a dedicated
Transformsmodule that handles:Example from
Anthropic::Transforms:Breaking Changes
Testing
Files Changed
Major additions:
lib/active_agent/providers/anthropic/transforms.rb(+353 lines)lib/active_agent/providers/open_ai/chat/transforms.rb(+364 lines)lib/active_agent/providers/open_ai/responses/transforms.rb(+228 lines)lib/active_agent/providers/open_ai/embedding/transforms.rb(+88 lines)lib/active_agent/providers/ollama/chat/transforms.rb(+135 lines)lib/active_agent/providers/ollama/embedding/transforms.rb(+160 lines)lib/active_agent/providers/open_router/transforms.rb(+134 lines)Major deletions:
schema.ymlfile (65,937 lines - was documentation only)Summary
This refactoring eliminates ~3,500 lines of custom provider types that we had to maintain and keep in sync with upstream APIs. By leveraging the official provider gems' native types, we've made ActiveAgent more maintainable, reliable, and future-proof while preserving full backward compatibility.
This refactoring positions ActiveAgent to scale more effectively while reducing technical debt and improving long-term maintainability.